-- CALC_DUNGEON_MONSTER_INIT_HP
-- 计算地牢怪物的初始血量

-------------------
-- @param hp_coef  hp系数
-- @param layer    地牢层数
return function(hp_coef, layer, layer_fix)
    -- b + ax
    local hp_b = 0.7 * layer_fix * (hp_coef + 10) / 20;
    local hp_a = hp_coef * (60 + layer_fix) / 800;
    local max_hp = 0;
    
    if layer_fix < 5 then
        hp_b = 0.4 * layer_fix * (hp_coef + 10) / 20;
    end

    if layer < 30 then
        -- 在比较小层的情况下，精确计算
        local hp_fix = math.modf(10 * hp_coef);
        local num = 28 * layer_fix * (hp_fix + 100) + (60 + layer_fix) * hp_fix * layer;

        if layer_fix < 5 then
            num = 16 * layer_fix * (hp_fix + 100) + (60 + layer_fix) * hp_fix * layer;
        end
        
        local deno = 8000;
        local ret = math.modf(num / deno);
        if num % deno ~= 0 then
            ret = ret + 1;
        end

        return ret;
    elseif layer < 40 then
        max_hp = hp_b + hp_a * layer * layer / 30;
    elseif layer < 50 then
        max_hp = hp_b + hp_a * layer * layer / 30 * layer / 40;
    elseif layer < 65 then
        max_hp = hp_b + hp_a * layer * layer / 30 * layer / 40 * layer / 50;
    else
        max_hp = hp_b + hp_a * layer * layer / 30 * layer / 40 * layer / 50 * layer / 65;
    end

    -- 为保证服务器客户端计算一致，先做如此处理
    max_hp = tonumber(string.format("%.2f", max_hp));
    return math.modf(math.ceil(max_hp));
end
